home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / XAMPP 1.4.14 / xampp-win32-1.4.14-installer.exe / xampp / mysql / scripts / mysql_fix_privilege_tables < prev    next >
Text File  |  2005-04-01  |  5KB  |  204 lines

  1. #!/bin/sh
  2. # This script is a wrapper to pipe the mysql_fix_privilege_tables.sql
  3. # through the mysql client program to the mysqld server
  4.  
  5. # Default values (Can be changed in my.cnf)
  6. password=""
  7. host="localhost"
  8. user="root"
  9. sql_only=0
  10. basedir=""
  11. verbose=0
  12. args=""
  13. port=""
  14. socket=""
  15. database="mysql"
  16. bindir=""
  17. print_defaults_bindir="."
  18.  
  19. file=mysql_fix_privilege_tables.sql
  20.  
  21. # The following test is to make this script compatible with the 4.0 where
  22. # the single argument could be a password
  23. if test "$#" = 1
  24. then
  25.   case "$1" in
  26.   --*) ;;
  27.   *) old_style_password="$1" ; shift ;;
  28.   esac
  29. fi
  30.  
  31. # The following code is almost identical to the code in mysql_install_db.sh
  32.  
  33. case "$1" in
  34.     --no-defaults|--defaults-file=*|--defaults-extra-file=*)
  35.       defaults="$1"; shift
  36.       ;;
  37. esac
  38.  
  39. parse_arguments() {
  40.   # We only need to pass arguments through to the server if we don't
  41.   # handle them here.  So, we collect unrecognized options (passed on
  42.   # the command line) into the args variable.
  43.   pick_args=
  44.   if test "$1" = PICK-ARGS-FROM-ARGV
  45.   then
  46.     pick_args=1
  47.     shift
  48.   fi
  49.  
  50.   for arg do
  51.     case "$arg" in
  52.       --basedir=*) basedir=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
  53.       --user=*) user=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
  54.       --password=*) password=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
  55.       --host=*) host=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
  56.       --sql|--sql-only) sql_only=1 ;;
  57.       --verbose) verbose=1 ;;
  58.       --port=*) port=`echo "$arg" | sed -e "s;--port=;;"` ;;
  59.       --socket=*) socket=`echo "$arg" | sed -e "s;--socket=;;"` ;;
  60.       --database=*) database=`echo "$arg" | sed -e "s;--database=;;"` ;;
  61.       --bindir=*) bindir=`echo "$arg" | sed -e "s;--bindir=;;"`
  62.                   print_defaults_bindir=$bindir
  63.           ;;
  64.       *)
  65.         if test -n "$pick_args"
  66.         then
  67.           # This sed command makes sure that any special chars are quoted,
  68.           # so the arg gets passed exactly to the server.
  69.           args="$args "`echo "$arg" | sed -e 's,\([^=a-zA-Z0-9_.-]\),\\\\\1,g'`
  70.         fi
  71.         ;;
  72.     esac
  73.   done
  74. }
  75.  
  76. # Get first arguments from the my.cfg file, groups [mysqld] and
  77. # [mysql_install_db], and then merge with the command line arguments
  78.  
  79. print_defaults=my_print_defaults
  80. for dir in ./bin /usr/local/bin /usr/local/bin extra $print_defaults_bindir/../bin $print_defaults_bindir/../extra
  81. do
  82.   if test -x $dir/my_print_defaults
  83.   then
  84.     print_defaults="$dir/my_print_defaults"
  85.     break
  86.   fi
  87. done
  88.  
  89. parse_arguments `$print_defaults $defaults mysql_install_db mysql_fix_privilege_tables`
  90. parse_arguments PICK-ARGS-FROM-ARGV "$@"
  91.  
  92. if test -z "$basedir"
  93. then
  94.   basedir=/usr/local
  95.   if test -z "$bindir"
  96.   then
  97.      bindir=/usr/local/bin
  98.   fi
  99.   execdir=/usr/local/libexec 
  100.   pkgdatadir=/usr/local/share/mysql
  101. else
  102.   if test -z "$bindir"
  103.   then
  104.     bindir="$basedir/bin"
  105.   fi
  106.   if test -x "$basedir/libexec/mysqld"
  107.   then
  108.     execdir="$basedir/libexec"
  109.   elif test -x "/usr/local/libexec/mysqld"
  110.   then
  111.     execdir="/usr/local/libexec"
  112.   else
  113.     execdir="$basedir/bin"
  114.   fi
  115. fi
  116.  
  117. if test -z "$password"
  118. then
  119.   password=$old_style_password
  120. fi
  121.  
  122. cmd="$bindir/mysql --no-defaults --force --user=$user --host=$host"
  123. if test ! -z "$password" ; then
  124.   cmd="$cmd --password=$password"
  125. fi
  126. if test ! -z "$port"; then
  127.   cmd="$cmd --port=$port"
  128. fi
  129. if test ! -z "$socket"; then
  130.   cmd="$cmd --socket=$socket"
  131. fi
  132. cmd="$cmd --database=$database"
  133.  
  134. if test $sql_only = 1
  135. then
  136.   cmd="cat"
  137. fi
  138.  
  139. # Find where first mysql_fix_privilege_tables.sql is located
  140. for i in $basedir/support-files $basedir/share $basedir/share/mysql \
  141.         $basedir/scripts /usr/local/share/mysql . ./scripts
  142. do
  143.   if test -f $i/$file
  144.   then
  145.     pkgdatadir=$i
  146.     break
  147.   fi
  148. done
  149.  
  150. sql_file="$pkgdatadir/$file"
  151. if test ! -f $sql_file
  152. then
  153.   echo "Could not find file '$file'."
  154.   echo "Please use --basedir to specify the directory where MySQL is installed"
  155.   exit 1
  156. fi
  157.  
  158. s_echo()
  159. {
  160.    if test $sql_only = 0
  161.    then
  162.      echo $1
  163.    fi
  164. }
  165.  
  166. s_echo "This script updates all the mysql privilege tables to be usable by"
  167. s_echo "MySQL 4.0 and above."
  168. s_echo ""
  169. s_echo "This is needed if you want to use the new GRANT functions,"
  170. s_echo "CREATE AGGREGATE FUNCTION, or the more secure passwords in 4.1"
  171. s_echo ""
  172.  
  173. if test $verbose = 1
  174. then
  175.   s_echo "You can safely ignore all 'Duplicate column' and 'Unknown column' errors"
  176.   s_echo "because these just mean that your tables are already up to date."
  177.   s_echo "This script is safe to run even if your tables are already up to date!"
  178.   s_echo ""
  179. fi
  180.  
  181. if test $verbose = 0
  182. then
  183.   cat $sql_file | $cmd > /dev/null 2>&1
  184. else
  185.   cat $sql_file | $cmd > /dev/null
  186. fi
  187. if test $? = 0
  188. then
  189.   s_echo "done"
  190. else
  191.   s_echo "Got a failure from command:"
  192.   s_echo "$cmd"
  193.   s_echo "Please check the above output and try again."
  194.   if test $verbose = 0
  195.   then
  196.     s_echo ""
  197.     s_echo "Running the script with the --verbose option may give you some information"
  198.     s_echo "of what went wrong."
  199.   fi
  200.   s_echo ""
  201.   s_echo "If you get an 'Access denied' error, you should run this script again and"
  202.   s_echo "give the MySQL root user password as an argument with the --password= option"
  203. fi
  204.